package work20241203_chap6oop;

/**
 * @author zdl
 * @date 2024/12/3
 */
class  Adult {
    private String name;
    private int age;
    private Child child;

    public Adult() {
    }

    public Adult(String name, int age, Child child) {
        this.name = name;
        this.age = age;
        this.child = child;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Child getChild() {
        return child;
    }

    public void setChild(Child child) {
        this.child = child;
    }
}

class Child {
    private String name;
    private int age;
    private Toy toy;

    public Child() {
    }

    public Child(String name, int age, Toy toy) {
        this.name = name;
        this.age = age;
        this.toy = toy;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Toy getToy() {
        return toy;
    }

    public void setToy(Toy toy) {
        this.toy = toy;
    }
}

class Toy {
    private double price;
    private String category;//类别
    private String color;

    public Toy() {
    }

    public Toy(double price, String category, String color) {
        this.price = price;
        this.category = category;
        this.color = color;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
}

public class Demo1 {
    public static void main(String[] args) {
        Toy toy = new Toy();
        toy.setCategory("小汽车");
        toy.setColor("红色");
        toy.setPrice(19.9);
        Child child = new Child();
        child.setToy(toy);
        child.setAge(9);
        child.setName("小天");
        Adult adult = new Adult();
        adult.setAge(33);
        adult.setChild(child);
        adult.setName("大天");
        System.out.println(adult.getName());
        System.out.println(adult.getAge());
        System.out.println(adult.getChild().getName());
        System.out.println(adult.getChild().getAge());
        System.out.println(adult.getChild().getToy().getCategory());
        System.out.println(adult.getChild().getToy().getColor());
        System.out.println(adult.getChild().getToy().getPrice());

    }
}
